#include "categorymodel.h"
#include "newspaper/newspapermanager.h"
#include "QDebug"

CategoryListModel::CategoryListModel(QObject *parent)
    : QAbstractListModel(parent), m_listCategory()
{
}

void CategoryListModel::setSourceInfo(const QList<int> &listSourceInfo)
{
    beginResetModel();
    m_listCategory = listSourceInfo;
    endResetModel();
}

void CategoryListModel::addSourceInfo(const int categoryId)
{
    beginInsertRows(QModelIndex(), rowCount(), rowCount());
    m_listCategory.append(categoryId);
    endInsertRows();
}

int CategoryListModel::rowCount(const QModelIndex & parent) const {
    Q_UNUSED(parent);
    return m_listCategory.count();
}

QVariant CategoryListModel::data(const QModelIndex & index, int role) const {
    if (index.row() < 0 || index.row() >= m_listCategory.count())
        return QVariant();

    int idCategory = m_listCategory[index.row()];
   if(role == IdRole)
        return idCategory;
    return QVariant();

}


QHash<int, QByteArray> CategoryListModel::roleNames() const {
    QHash<int, QByteArray> roles;
    roles[IdRole] ="idcategorydelegate";

    return roles;
}

void CategoryListModel::clear()
{
    beginResetModel();
    m_listCategory.clear();
    endResetModel();
}
